package portal.controller;

import portal.dao.ScheduleJobDetailDao;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;


/**
 * Servlet implementation class GetTaskState
 * 已经被废弃使用了，新方法在 JobController中
 */
@Deprecated
public class GetJobDetailServlet extends BaseServlet {
    private static final long serialVersionUID = 1L;
    @Autowired
    ScheduleJobDetailDao scheduleJobDetailDao ;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetJobDetailServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String jobId = request.getParameter("jobId");
//        获取对应的作业详情
        
        JSONArray result = JSONArray.fromObject(scheduleJobDetailDao.getJobDetail(jobId));
//        返回前端对应作业详细信息json
        if (result.isEmpty()){
            response.getWriter().write("null");
        }else{
            response.getWriter().write(result.getJSONObject(0).toString());
        }
    }

}
